package cn.lls.controller.employee;

import cn.lls.base.result.R;
import cn.lls.entity.company.DepartmentEntity;
import cn.lls.service.IDepartmentService;
import cn.lls.service.IEmployeeBaseService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

/**
 * <p>
 *  部门信息控制器
 * </p>
 *
 * @author 划水艺术家
 * @since 2022-11-15
 */
@RestController
@RequestMapping("/emp/department")
@Api(tags = "公司部门信息控制器")
@Slf4j
public class EMPDepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @Autowired
    private IEmployeeBaseService employeeBaseService;

    @GetMapping("/{companyId}")
    @ApiOperation(value = "获取所有部门信息", notes = "获取所有部门信息",
            response = R.class, httpMethod = "GET")
    public R getAllDepartment(
            @ApiParam(required = true, value = "部门Id")
            @PathVariable("companyId")
            @NotEmpty(message = "必须具备公司Id") Long companyId){
        LambdaQueryWrapper<DepartmentEntity> queryWrapper =  new LambdaQueryWrapper<>();
        queryWrapper.eq(DepartmentEntity::getCompanyId, companyId);
        return R.success(departmentService.list(queryWrapper));
    }
}

